package com.zjuee.web.ledger.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjuee.base.dto.common.plan.PlanPDeviceDto;
import com.zjuee.service.PlanPDeviceService;
import com.zjuee.base.model.common.plan.PlanPDevice;
import com.zjuee.web.ledger.mapper.PlanPDeviceMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author ding jinli
 * @since 1.0
 */
@Slf4j
@Service
public class PlanPDeviceServiceImpl implements PlanPDeviceService {
    @Resource
    PlanPDeviceMapper planPDeviceMapper;


    @Override
    public Long add(PlanPDevice type) {
        int state = planPDeviceMapper.insert(type);
        if (1 == state) {
            return type.getId();
        }
        return null;
    }

    @Override
    public boolean delete(Long id, Long validateId) {
        PlanPDevice planPDevice = planPDeviceMapper.selectById(id);
        if (validateId.equals(planPDevice.getWpiId())) {
            int type = planPDeviceMapper.deleteById(id);
            if (1 == type) {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean update(PlanPDevice type) {
        int state = planPDeviceMapper.updateById(type);
        if (1 == state) {
            return true;
        }
        return false;
    }

    @Override
    public PlanPDevice selectById(Long id, Long validateId) {
        PlanPDevice planPDevice = planPDeviceMapper.selectById(id);
        if (validateId.equals(planPDevice.getWpiId())) {
            return planPDevice;
        }
        return null;
    }

    @Override
    public Page<PlanPDevice> list(PlanPDeviceDto dto) {
        return null;
    }

    @Override
    public LambdaQueryWrapper<PlanPDevice> fuzzyQuery(PlanPDeviceDto dto) {
        return null;
    }
}
